using System.Collections.Generic;

namespace OpenBlock.ResourceManagement
{
    public abstract class Module<TEntry>
    {
        public abstract string Name { get; }
        public abstract void OnLoad();

        private Dictionary<string, ushort> resMapId = new Dictionary<string, ushort>();
        private List<TEntry> entries = new List<TEntry>();

        internal void RegisterEntry(string name, TEntry entry)
        {
            resMapId.Add(name, (ushort)entries.Count);
            entries.Add(entry);
        }

        internal ushort? GetIndex(string name)
        {
            if (resMapId.TryGetValue(name, out ushort idx)) return idx;
            return null;
        }

        internal TEntry GetEntry(ushort id)
        {
            return entries[id];
        }
    }
}